#include "helper/sqlite/AutoDB.h"

#include "helper/sqlite/MemoryDB.h"
#include "helper/sqlite/FileDB.h"
#include "helper/sqlite/DB.h"

namespace helper {
namespace sqlite {

AutoDB AutoDB::make_memory(const std::string & name) {
  std::unique_ptr<IDB> db(new MemoryDB(name));
  return AutoDB(std::move(db));
}
AutoDB AutoDB::make_file(const std::string & name, const std::string & dir) {
  std::unique_ptr<IDB> db(new FileDB(name, dir));
  return AutoDB(std::move(db));
}
AutoDB AutoDB::make_db(const std::string & url){
  std::unique_ptr<IDB> db(new DB(url));
  return AutoDB(std::move(db));
}


AutoDB::AutoDB()
{
}
void AutoDB::__move(AutoDB && other){
  _db.swap(other._db);
  _decorator.swap(other._decorator);
}
AutoDB::AutoDB(AutoDB && other) 
{
  __move(std::move(other));
}
AutoDB & AutoDB::operator =(AutoDB && other) {
  __move(std::move(other));
  return *this;
}

AutoDB::~AutoDB() {
}   
//assert(db != nullptr);
AutoDB::AutoDB(std::unique_ptr<IDB> && db)
: _db(std::move(db))
, _decorator(new AutoDBDecorator(*_db))
{
}

}//namespace sqlite
}//namespace helper
